<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var arr = function (nums) {
    nums.sort((a, b) => a - b)
    let i = 0
    let res = 0
    for (const num of nums) {
      if (num > nums[i]) {
        i++
        res++
      }
    }
    return res
  };
  console.log(arr(nums = [1, 3, 5, 2, 1, 3, 1]));
</script>

</html>